package xyz.o0o0o.demo.springMVC.controller.RESTful;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import xyz.o0o0o.demo.springMVC.vo.User;

@Controller("userController")
@RequestMapping(value = "user")
public class UserController {
    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    @ResponseBody
    public Object get(@PathVariable Integer id) {
        System.out.println(id);
        if (1 == id) {
            return new User(1, "joker", 100, true);
        } else {
            return new User(2, "luna", 5, false);
        }
    }

    @ResponseBody
    @RequestMapping(value = "{id}", method = RequestMethod.DELETE)
    public void delete(@PathVariable int id) {
        System.out.println("delete user,user id:" + id);
    }
    
    @RequestMapping( method = RequestMethod.POST)
    public @ResponseBody Object post(User user){
        System.out.println("create user,name:"+user.getName());
        return user;
    }

}
